package com.javasm.controller;

import com.javasm.utils.JwtUtil;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author：MoDebing
 * @Version：1.0
 * @Date：2022-09-04-20:19
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 解析jwt
     * @param request
     * @param authentication
     * @return
     */
    @RequestMapping("/getcurrentUserInfo")
    public Object getUserInfo(HttpServletRequest request,Authentication authentication) throws Exception {

        String header = request.getHeader("Authorization");
        String token = header.split(" ")[header.split(" ").length-1];

        return JwtUtil.parseJWT(token);
    }

}
